#ifndef CONFIGFILE_H
#define CONFIGFILE_H

#include <QObject>              // 基类
#include <QString>              // 字符串类
#include <QSettings>            // 配置文件操作类
#include <QVariant>             // 基础数据类型类

#define DEFAULT_FILENAME        "config.ini"

/* define prase string */
#define USER_WEB_URL            "USER/web_url"
#define USER_NAME               "USER/name"
#define USER_PASSWORD           "USER/password"
#define USER_AUTO_LOGIN         "USER/auto_login"
#define USER_SAVE_PASSWORD      "USER/save_password"
#define USER_PHPSESSID          "USER/PHPSESSID"

class ConfigFile : public QObject
{
    Q_OBJECT

    enum Status {
        NO_ERROR = 0,
    };

public:
    explicit ConfigFile(QString path, QObject *parent = nullptr);
    ~ConfigFile();
    void setValue(const QString &key, const QVariant &value);
    QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;


signals:
private: /* var */
    QSettings *settings;
    QString settingsFilePath;
    Status status;

private: /* fun */
    Status autoSetDefaultConfig();

};

#endif // CONFIGFILE_H
